using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using EcosimBase;

namespace EcosimDemo
{
    public partial class Form1 : Form
    {
        SampleCreature Sample1;

        public Form1()
        {
            InitializeComponent();
            Field.Height = 500;
            Field.Width = 500;
            Sample1 = new SampleCreature(10, 10);
            Field.Creatures.Add(Sample1);
            Sample1.MovedEvent += new MovedHandler(Sample1_MovedEvent);
            Sample1.Start();

            Random rand = new Random();
            for (int i = 0; i < 100; i++)
            {
                Field.Plants.Add(new Plant(rand.Next(0, 500), rand.Next(0, 500), rand.Next(0, 10)));
            }
        }

        void Sample1_MovedEvent(MovedEventArgs e)
        {
            this.Invalidate();
            Console.WriteLine("Moved");
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            Pen plantPen = new Pen(Color.Green);
            foreach (Plant p in Field.Plants)
            {
                g.DrawRectangle(plantPen, new Rectangle(p.X, p.Y, 1, 1));
            }

            Pen creaturePen = new Pen(Color.Red);
            foreach (Creature c in Field.Creatures)
            {
                g.DrawRectangle(creaturePen, new Rectangle(c.Data.X, c.Data.Y, 1, 1));
            }
            Console.WriteLine("Refreshed");
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            Sample1.Dispose();
        }

        private void btnRestart_Click(object sender, EventArgs e)
        {
            Sample1.Start();
        }
    }
}